package io.hepu.robotize.util;

import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

public class Randoms {
    static String CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

    public static String getRandom() {
        return String.format("%04d", new Random().nextInt(9999));
    }

    public static String getRandom(int length) {
        final StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            int index = (int) Math.floor(Math.random() * CHARACTERS.length());
            sb.append(CHARACTERS.charAt(index));
        }
        return sb.toString();
    }

    public static List<Integer> getRandomInts(int start, int bound, int size) {
        if (bound <= 0 || bound <= start) {
            return Collections.emptyList();
        }
        if (size > bound) {
            size = bound;
        }
        return new Random().ints(start, bound).distinct().limit(size).boxed().collect(Collectors.toList());
    }
}
